package component

import cn.hutool.core.swing.clipboard.ClipboardListener
import cn.hutool.core.swing.clipboard.ClipboardUtil
import java.awt.Image
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.Transferable

/**
 * @author zooy
 * @since 2024/7/26-17:57
 */
abstract class ComplexClipboardListener: ClipboardListener {

    override fun onChange(clipboard: Clipboard, contents: Transferable): Transferable? {
        if (contents.isDataFlavorSupported(DataFlavor.imageFlavor)) {
            return onChange(clipboard, ClipboardUtil.getImage(contents));
        } else if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            return onChange(clipboard, ClipboardUtil.getStr(contents));
        }
        return null
    }

    abstract fun onChange(clipboard: Clipboard, contents: Image): Transferable?

    abstract fun onChange(clipboard: Clipboard, contents: String): Transferable?

}
